# coding=utf-8
# coding=utf-8
from random import choice, random


CLS_NUM = 10
WEEK = 5
SECTION = 6
LESSON = 9
QUOTA = 6 # 一个班级(教师)每天最多6课时
TESCHER = CLS_NUM * WEEK * SECTION / QUOTA +1 # 51
TESCHER = 51




A = list(set([str(i) for i in range(1, WEEK*SECTION+1)]))   # 课时集合
L = list(set([str(i) for i in range(1, LESSON+1)]))         # 课程集合
C = list(set([str(i) for i in range(1, CLS_NUM+1)]))        # 班级集合
T = list(set([str(i) for i in range(1, TESCHER+1)]))        # 教师集合

A.sort(key=lambda i:int(i))
L.sort(key=lambda i:int(i))
C.sort(key=lambda i:int(i))
T.sort(key=lambda i:int(i))


d_T = {t:0 for t in T} # 教师-课时
d_LT = {}              # 教师-课程
def get_T(l):
    global d_T
    global T
    _T = []
    for t in d_T:
        if d_T[t] < QUOTA and QUOTA - d_T[t] == Lt[l]:
            _T.append(t)
    else:
        _T = T
    t = choice(_T)
    d_T[t] += Lt[l]
    return t

# 1 2 3 -- 6
# 4 5 6 -- 3
# 7 8 9 -- 1
Lt = {l: int(l) < 4 and 6 or int(l) < 7 and 3 or 1 for l in L} # 1.课程-课时表
CL = {c:list(L) for c in C}                                    # 2.班级-课程表
TCL = {c+'-'+l: get_T(l) for c in CL for l in CL[c]}           # 3.班级-课程-教师表
CTA = {cl.split('-')[0]+'-'+TCL[cl]:Lt[cl.split('-')[1]] for cl in TCL} # 4.教师—班级—时间分配表
cta = [(i, CTA[i]) for i in CTA]
cta.sort(key=lambda i: [int(i[0].split('-')[0]), int(i[0].split('-')[1])])
X=[]
for c in C:
    X.append([])
    for t in T:
        X[int(c)-1].append(CTA.get(c+'-'+t, '-'))

if __name__ == '__main__':
    print u'课时集合:', A
    print u'课程集合:', L
    print u'班级集合:', C
    print u'教师集合:', T
    print u'1.课程-课时:', Lt
    print u'2.班级-课程:', CL
    print u'3.班级-课程-教师:', TCL
    print u'教师-课时:', d_T
    print u'4.教师—班级—时间分配表', CTA
    for i in cta:
        print i
    for l in X:
        for i in l:
            print i,
        print
